package cn.anl.service.impl;

import cn.anl.constant.CloudConstant;
import cn.anl.pojo.HotComment;
import cn.anl.service.CloudMusicService;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author 安奈
 * @CreateTime 2024-07-11  19:43
 * @Desc TODO
 */
@Service
public class CloudMusicServiceImpl implements CloudMusicService {
    @Resource
    public RestTemplate restTemplate;
    public List<HotComment> getHotComments() {
        List<HotComment> hotComments;
        try {
          String value= restTemplate.getForObject(CloudConstant.HOT_COMMENTS_URL,String.class);
            hotComments = JSONUtil.toList(value, HotComment.class);
        } catch (RestClientException e) {
            throw new RuntimeException("与网易云接口服务器通信时出错", e);
        }
        return hotComments;
    }
}
